package plug.QCMPlugin;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import plug.Introspection;

import view.Param;
import view.Professeurs.ProfPage;

@SuppressWarnings("serial")
public class QCMPanelProf extends JPanel implements ActionListener {

	private JTextField tQuestion, tChoices, tAnswer;
	private JButton bEnter = new JButton("Valider");

	public QCMPanelProf() {

		// Alignement vertical des conteneurs
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		// Ajout de la transparence
		this.setOpaque(false);

		// Creation des conteneurs
		JLabel lTitre = new JLabel("QCM");
		JPanel pZones = new JPanel();
		JLabel lQuestion = new JLabel("Question :");
		JLabel lChoices = new JLabel("Choix possibles :");
		JLabel lAnswer = new JLabel("R\u00E9ponse : ");
		tQuestion = new JTextField(20);
		tChoices = new JTextField(20);
		tAnswer = new JTextField(20);
		tChoices.setText("choix1,choix2,choix3");
		tAnswer.setText("reponse1, reponse2");
		
		// Ajustements du panel central
		pZones.setLayout(new GridLayout(3, 0)); // 3 conteneurs (lignes)
		pZones.setOpaque(false);
		pZones.setBorder(Param.wideMargin);

		// Couleurs
		lTitre.setForeground(Param.fontColor);

		// Ajout des marges
		this.setBorder(Param.shortMargin);

		// Ajout des conteneurs
		this.add(lTitre);
		pZones.add(lQuestion);
		pZones.add(tQuestion);
		pZones.add(lChoices);
		pZones.add(tChoices);
		pZones.add(lAnswer);
		pZones.add(tAnswer);
		this.add(pZones);
		this.add(bEnter);

		// Ajout des ecouteurs
		bEnter.addActionListener(this);

	}

	public void actionPerformed(ActionEvent event) {

		if (event.getSource() == bEnter ) {

			QCM q = (QCM) Introspection.exo;
			q.creer(tQuestion.getText(), tChoices.getText(), tAnswer.getText());
			
			ProfPage.center.update(new JPanel());			// Effacement du panel
			String message = "Validation effectu\u00E9e";
			JOptionPane.showMessageDialog(null, message, "Validation", JOptionPane.INFORMATION_MESSAGE);

		}

	}

}
